package com.service;

import cn.hutool.core.date.DateTime;
import com.mapper.P_inforDao;
import com.mapper.Title_reviewDao;
import com.util.P_infor;
import com.util.Process_review;
import com.util.Result;
import com.util.Title_review;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Title_reviewService {
    @Resource
    private Title_reviewDao title_reviewDao;
    @Resource
    private Process_reviewService process_reviewService;
    @Resource
    private P_inforService p_inforService;

    public Result<?> apply(Title_review title_review){
        title_reviewDao.insert(title_review);
        Process_review process_review=new Process_review();
        process_review.setpAccount(title_review.getpAccount());
        process_review.setStatue("正在审核");
        process_review.setStep("提交申请");
        DateTime dateTime=new DateTime();
        process_review.setDatetime(dateTime.toString());
        process_reviewService.insert1(process_review);
        Result result=new Result();
        Result r=result.success(result);
        return r;
    }
    public List<Title_review> search(Title_review title_review){
        System.out.println(title_review);
        return title_reviewDao.select(title_review);
    }
    public Result<?> handle_apply(Title_review title_review){
        P_infor p_infor=p_inforService.selectByPId(title_review.getpId());
        Process_review process_review=new Process_review();
        process_review.setpAccount(title_review.getpAccount());
        process_review.setcName(title_review.getcName());
        process_review.setpAccount(p_infor.getpAccount());
        process_review.setStatue("正在审核");
        process_review.setStep("单位审核");
        DateTime dateTime=new DateTime();
        process_review.setDatetime(dateTime.toString());
        process_review.setResult(title_review.getResult());
        title_reviewDao.update(title_review);
        process_reviewService.insert2(process_review);
        Result result=new Result();
        Result r=result.success(result);
        return r;
    }
}
